//
//  PicAlbumViewController.m
//  YouGoWeGo
//
//  Created by LiuFei on 14/11/26.
//  Copyright (c) 2014年 LiuFei. All rights reserved.
//

#import "PicAlbumViewController.h"
#import "UIImageView+WebCache.h"
#import "AreaModel.h"

@interface PicAlbumViewController ()<UIScrollViewDelegate>

@end

@implementation PicAlbumViewController

- (void)dealloc
{
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    [self createScroll];
}


- (void)createScroll
{
    self.bigScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height / 4, self.view.frame.size.width, self.view.frame.size.height - 64)];
    [_bigScroll setContentSize:CGSizeMake(self.view.frame.size.width * [_albumArray count], 0)];
    [_bigScroll setScrollEnabled:YES];
    [_bigScroll setPagingEnabled:YES];
    [_bigScroll setShowsHorizontalScrollIndicator:YES];
    
    
    
    for (int i = 0; i < [_albumArray count]; i ++) {
        
        UIScrollView *smallScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height / 2)];
        [smallScroll setContentSize:CGSizeMake(_bigScroll.frame.size.width, self.view.frame.size.height / 2)];
        [smallScroll setScrollEnabled:YES];
        [smallScroll setDelegate:self];
        [smallScroll setMaximumZoomScale:3];
        [smallScroll setMinimumZoomScale:0.5];
        [smallScroll setZoomScale:1];
        [smallScroll setShowsHorizontalScrollIndicator:YES];
        
        NSMutableDictionary *pinfoDic = [self.pInfoArray objectAtIndex:i];
        NSString *str = [pinfoDic objectForKey:@"photo_info"];
        CGFloat image_h = 0;
        CGFloat image_w = 0;
        if ([str length] == 6) {
            image_h = [[str substringWithRange:NSMakeRange(0, 3)] floatValue];
            image_w = [[str substringWithRange:NSMakeRange(3, 3)] floatValue];
        } else {
            image_h = [[str substringWithRange:NSMakeRange(0, 4)] floatValue];
            image_w = [[str substringWithRange:NSMakeRange(4, 4)] floatValue];
        }
        
        AreaModel *model = [self.albumArray objectAtIndex:i];
        
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, image_h * self.view.frame.size.width / image_w)];
        [image setImageWithURL:[NSURL URLWithString:model.photo_s]];
        [smallScroll addSubview:image];
        [_bigScroll addSubview:smallScroll];
        [image release];
        [smallScroll release];
    }
    
    [self.view addSubview:_bigScroll];
    [_bigScroll release];
}

#pragma mark - 缩放当前的图片
//- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
//{
//    NSArray *arr = scrollView.subviews;
//    UIImageView *image = [arr objectAtIndex:0];
//    return image;
//}

@end
